package com.rabbit.controller;

import com.rabbit.entity.Device;
import com.rabbit.entity.Notice;
import com.rabbit.entity.Room;
import com.rabbit.entity.User;
import com.rabbit.mq.NoticeFanoutProducer;
import com.rabbit.mq.NoticeTopicProducer;
import com.rabbit.mq.SyncDirectProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yuhuan
 * @date 2025/4/18
 */
@RestController
@RequestMapping("/rabbit")
public class RabbitController {

    @Autowired
    SyncDirectProducer syncDirectProducer;

    @Autowired
    NoticeFanoutProducer noticeFanoutProducer;

    @Autowired
    NoticeTopicProducer noticeTopicProducer;

    @PostMapping("/sent/user")
    public User sentUser(@RequestBody User user) {
        syncDirectProducer.sendUserSyncMessage(user);
        return user;
    }

    @PostMapping("/sent/room")
    public Room sentRoom(@RequestBody Room room) {
        syncDirectProducer.sendRoomSyncMessage(room);
        return room;
    }

    @PostMapping("/sent/device")
    public Device sentDevice(@RequestBody Device device) {
        syncDirectProducer.sendDeviceSyncMessage(device);
        return device;
    }

    @PostMapping("/sent/notice")
    public Notice sentNotice(@RequestBody Notice notice) {
        noticeFanoutProducer.sendNoticeMessage(notice);
        return notice;
    }

    @PostMapping("/sent/hotelNotice")
    public Notice sentHotelNotice(@RequestBody Notice notice) {
        noticeTopicProducer.sendHotelMessage(notice);
        return notice;
    }

    @PostMapping("/sent/adminNotice")
    public Notice sentAdminNotice(@RequestBody Notice notice) {
        noticeTopicProducer.sendAdminMessage(notice);
        return notice;
    }
}
